package com.project.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.EmailBean;
import com.project.bean.ReceiveBean;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface IReceiveMapper extends BaseMapper<ReceiveBean> {
    /**
     * 按当前用户id，动态条件分页查询发送邮件
     *
     * @param page      分页对象
     * @param theme     主题
     * @param startDate 起始日期
     * @param endDate   结束日期
     * @param userId    当前用户id
     * @return 邮件集合
     */
    IPage<ReceiveBean> cutByItem(@Param("page") Page page,
                               @Param("theme") String theme,
                               @Param("startDate") LocalDate startDate,
                               @Param("endDate") LocalDate endDate,
                               @Param("userId") Integer userId);
    @Select("select re.*,e.pk_emailId,e.e_theme,e.e_content,e.e_path,e.fk_authorId,u.pk_userId,u.u_realName from " +
            "t_receive re left join t_email e on re.fk_emailId=e.pk_emailId left join t_user u on e.fk_authorId = u.pk_userId" +
            " where re.fk_receiverId=#{receiverId} and re.fk_emailId=#{emailId}")
    @ResultMap("emailMap")
    public EmailBean receiveReadEmail(@Param("emailId") Integer emailId,@Param("receiverId") Integer receiverId);
}
